package com.tjwx.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Auther: guyuefei
 * @Date: 2018/5/14 11:29
 * @Description: 格式化util类
 * @Usefor:
 * @param:
 * @Response:
 */
public class DateFormatUtil {
    public static final String date_pattern_1 =  "yyyy-MM-dd HH:mm:ss";
    public static final String date_pattern_2 =  "yyyy-MM-dd ";

    public static String DateFormat(Date date,String pattern){
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        if(date == null){
            date = new Date();
        }
        return sdf.format(date);
    }
    public static String DateFormat(String pattern){
        return DateFormat(null,pattern);
    }

    /**
     * 返回前几天后者后几天
     * 前几天为负，后几天为正
     * @param days
     * @param pattern
     * @return
     */
    public static String DateFormat(int days,String pattern){
        Date date=new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, days);
        return DateFormat(calendar.getTime(),pattern);
    }

    public static String DateFormat(){
        return DateFormat(null,date_pattern_1);
    }

    public static String getLongTime(){
        return new Date().getTime() + "";
    }

    public static long getTimeLong(){
        return new Date().getTime();
    }

}
